/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2023.
 * Description: debugll header file
 * Author: pengyunlong <pengyunlong@huawei.com>
 * Create: 2022-05-10
 */

#ifndef PRINT_H
#define PRINT_H

#include <linux/types.h>

#define UART_PHYS_ADDR_IN_BOOT_ARGS 1
#define UART_TYPE_IN_BOOT_ARGS 2

extern void printascii(const char *string, unsigned long uart_pa,
		unsigned long uart_va, unsigned long placeholder, unsigned long type);
extern void print_num(const unsigned long x, unsigned long uart_pa,
		unsigned long uart_va, unsigned long placeholder, unsigned long type);

extern unsigned long uart_virt_addr;
extern u64 boot_args[];

/* debugll api can be called before earlycon initialization in kernel booting. */
static inline void debugll_str(const char *string)
{
	unsigned long addr = boot_args[UART_PHYS_ADDR_IN_BOOT_ARGS];
	unsigned long type = boot_args[UART_TYPE_IN_BOOT_ARGS];

	if (addr != 0)
		printascii(string, addr, uart_virt_addr, 0, type);
}

static inline void debugll_num(const unsigned long x)
{
	unsigned long addr = boot_args[UART_PHYS_ADDR_IN_BOOT_ARGS];
	unsigned long type = boot_args[UART_TYPE_IN_BOOT_ARGS];

	if (addr != 0)
		print_num(x, addr, uart_virt_addr, 0, type);
}
#endif /* PRINT_H */
